layui.use(['form','layer','table','laytpl'],function(){
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        laytpl = layui.laytpl,
        table = layui.table;

    //用户列表
	
	
	
	
    var tableIns = table.render({
        elem: '#foodmenuList',
        url : 'http://127.0.0.1:88/index.php/font/Font/renwuList?id='+localStorage.login_font_name,
        cellMinWidth : 95,
        page : true,
        height : "full-125",
        limits : [10,15,20,25],
        limit : 20,
        id : "renwuListTable",
		totalRow: true,
        cols : [[
            {type: "checkbox", fixed:"left", width:50},
            {field:'renwu_font_id', title:'ID', width:70, fixed: 'left', unresize: true, sort: true, totalRowText: '合计'},
            {field: 'renwu_good_shop', title: '所属店铺', align:"center"},
            {field: 'renwu_good_searchWord', title: '搜索词', align:'center'},
            {field: 'renwu_good_money', title: '佣金', width:60, align:'center'},
			{title: '审核状态', templet:'#weishenhe',width:100, align:"center"},
            {field: 'renwu_addTime', title: '添加时间',width:170, align:'center'}
			,{field: 'renwu_isDo', title: '提交', align:'center',templet:function(d){
            	if(d.renwu_isDo==0){
            		return '<button class="layui-btn layui-btn-sm layui-btn-danger" id="Submit" lay-event="Submit">未提交</button>'+'<button class="layui-btn layui-btn-sm layui-btn-danger" id="font_del" lay-event="font_del">取消任务</button>';
            	}else{
					return '<button class="layui-btn layui-btn-sm layui-btn-disabled">已提交</button>'+'<button class="layui-btn layui-btn-sm layui-btn-danger" id="font_del" lay-event="font_del">取消任务</button>';
            	}
            	
                
            }},
        ]]
    });
	$("#smb").click(function() {
		
		layer.msg('----------------');
	})
    //搜索【此功能需要后台配合，所以暂时没有动态效果演示】
    $(".search_btn").on("click",function(){
    	var type = $(this).data('type');
    	//console.log(type);
        if($(".searchVal").val() != ''){
            table.reload("renwuListTable",{
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                method:'post',
                url:'http://127.0.0.1:88/index.php/renwu/renwu/renwuSearch',
                where: {
                    key: $(".searchVal").val(),  //搜索的关键字
                    user_name:localStorage.login_name
                },
                contentType: 'application/json',
                done: function(res, curr, count){
                  //this.where={};
                  //不清空，有问题：搜索条件会保留
                  //清空，  有问题：分页的时候没有搜索条件了,分页会受到影响
              }
            })
        }else{
            layer.msg("请输入搜索的内容");
        }
    });

   
	//刷新renwu_refresh
	$(".renwu_refresh").click(function(){
        tableIns.reload();
    })
	

    //列表操作
    table.on('tool(foodmenuList)', function(obj){
        var layEvent = obj.event,
            data = obj.data;
		id = data.renwu_id;
		console.log(id);
        if(layEvent === 'Submit'){ //编辑
			$("#Submit").attr("disabled", true); //存储按钮禁用
			$("#Submit").html("已提交");
			$("#Submit").attr("class", 'layui-btn layui-btn-sm layui-btn-disabled'); //渲染
        	$.ajax({ //结束时间
				type: 'POST',
				url: "http://127.0.0.1:88/index.php/font/Font/Submit",
				dataType: "text",
				data: "id="+id,
				success: function(sss) {
					layer.msg(sss);
				}
			});
            
        }
		else if(layEvent === 'weishenhe'){
		
		else if(layEvent === 'font_del'){ //删除
            layer.confirm('确定删除？',{icon:3, title:'提示信息'},function(index){
                $.get("http://127.0.0.1:88/index.php/font/Font/fontDel",{
                    id : data.renwu_font_id  //将需要删除的newsId作为参数传入
                },function(data){
                	if(data.code==200){
                		layer.msg(data.msg);
                		setTimeout(function(){
                			tableIns.reload();
                    		layer.close(index);
                		},1000);
                	}else{
                		layer.msg(data.msg);
                	}
                })
            });
        }
    });

})